#include <iostream>
#include <thread>
// compile: g++ -o thread_local thread_local.cc -std=c++11
// run: ./thread_local
using namespace std;
void func1() {
  // thread_local int count = 0;
  int count = 0;
  for (int i = 0; i < 100; i++) {
    cout << "count = " << count << ", in thread: " << std::this_thread::get_id()
         << endl;
    count++;
  }
}
void func2() {
  thread_local int count = 100;
  for (int i = 0; i < 10; i++) {
    cout << "count = " << count << ", in thread: " << std::this_thread::get_id()
         << endl;
    count--;
  }
}
int main() {
  std::thread t1(func1);
  std::thread t2(func1);
  t1.join();
  t2.join();
  return 0;
}
// TODO:没体现出thread_local的作用啊